package main

func sortArrayByParity(nums []int) []int {
	left, right := 0, len(nums)-1

	for true {
		for left < right {
			if nums[left]%2 == 1 {
				break
			}
			left++
		}

		for right > left {
			if nums[right]%2 == 0 {
				break
			}

			right--
		}

		temp := nums[left]
		nums[left] = nums[right]

		nums[right] = temp

		if left >= right {
			break
		}

	}

	return nums
}
